package com.ting.controller;


import com.google.common.collect.Lists;
import com.ting.entity.Mnu;
import com.ting.mapper.MnuMapper;
import com.ting.service.IMnuService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ting.utils.iterateMenus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2021-12-14
 */
@RestController
@RequestMapping("/mnu")
public class MnuController {

    @Resource
    MnuMapper mnuMapper;


    iterateMenus iterateMenus = new iterateMenus();

    @RequestMapping("/getMenuTree")
    public List<Mnu> getMenuTree(){
        // 根据父id查询
        List<Mnu> menusBase = mnuMapper.selectByPid("0");
        // 查询全部的子菜单
        List<Mnu> menuLNotBase = mnuMapper.selectAllNotBase();

        for (Mnu mnu : menusBase){
            List<Mnu> mnus = iterateMenus.iterateMenus( menuLNotBase, mnu.getId() );
            mnu.setMnuChildren( mnus );
        }
        return menusBase;
    }

}
